package com.chengcheng.tuan.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.chengcheng.tuan.R;
import com.chengcheng.tuan.R.id;
import com.chengcheng.tuan.R.layout;
import com.chengcheng.tuan.activity.DetailActivity;

public class ListFragment extends Fragment {
	private ListView listview;
	private ViewGroup header;

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		listview = (ListView) getView().findViewById(R.id.list);
		header = (ViewGroup) getActivity().getLayoutInflater().inflate(
				R.layout.listheader_list, null);
		listview.addHeaderView(header);
		listview.setAdapter(new BaseAdapter() {

			public View getView(int arg0, View arg1, ViewGroup arg2) {
				if (arg1 != null) {
					return arg1;
				} else {
					return getActivity().getLayoutInflater().inflate(
							R.layout.listitem_hotel_poi, null);
				}
			}

			@Override
			public long getItemId(int arg0) {
				// TODO Auto-generated method stub
				return arg0;
			}

			@Override
			public Object getItem(int arg0) {
				// TODO Auto-generated method stub
				return arg0;
			}

			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				return 20;
			}
		});
		listview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent = new Intent(getActivity(), DetailActivity.class);
				startActivity(intent);
			}

		});
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_list, null);
	}
}
